﻿/*======================================================================
== Copyright : BlueCurve (c)
== Licence   : Gnu/GPL v2.x
== Author    : Teddy Albina
== Email     : bluecurveteam@gmail.com
== Web site  : http://www.codeplex.com/BlueCurve
========================================================================*/
using System.ServiceModel;
using BlueCurve.IRemoteOperations;
using System;

namespace WebCrawler
{
    /// <summary>
    /// Client wcf
    /// </summary>
    public class Tcpclient
    {
        #region IWebCrawler Membres

        /// <summary>
        /// Arret de l'application
        /// </summary>
        public static event EventHandler _StopApplication;
        /// <summary>
        /// Redemarrage de l'application
        /// </summary>
        public static event EventHandler _RestartApplication;

        /// <summary>
        /// Demande de données au scheduler
        /// </summary>
        public string GetQueueForDownload()
        {
            try
            {
                ChannelFactory<IWebScheduler> channelFactory = new ChannelFactory<IWebScheduler>("Scheduler");
                IWebScheduler _server = channelFactory.CreateChannel();
                return _server.SendQueue();
            }
            catch
            {
                return null;
            }
        }
        
        #endregion



        #region 'Repository'

        /// <summary>
        /// Ajoute un nouveau fichier au repository
        /// </summary>
        /// <param name="path">chemin du fichier</param>
        /// <param name="typeoffile">type de fichier</param>
        /// <returns>bool</returns>
        public bool AddFileToRepository(string path, string typeoffile)
        {
            try
            {
                ChannelFactory<IRepository> channelFactory = new ChannelFactory<IRepository>("Repository");
                IRepository _repository = channelFactory.CreateChannel();
                _repository.AddFile(path, typeoffile);
                return true;
            }
            catch
            {
                return false;
            }
        }   

        #endregion



        #region IRemoteOperationsBase Membres

        /// <summary>
        /// Redemarre l'application
        /// </summary>
        public void RestartApplication()
        {
            _RestartApplication("", EventArgs.Empty);
        }


        /// <summary>
        /// Arreter l'application
        /// </summary>
        public void StopApplication()
        {
            _StopApplication("", EventArgs.Empty);
        }

        #endregion
    }
}
